package 结构型.代理;

public class JdkProxy {
    public static void main(String[] args) {

        IPrinter p = (IPrinter) java.lang.reflect.Proxy.newProxyInstance(Printer.class.getClassLoader(), Printer.class.getInterfaces(),
                (proxy, method, arg) -> {
            System.out.println(method);
            System.out.println("------a");
            method.invoke(Printer.class.newInstance());
            System.out.println("-------b");
            return proxy;
        });

        p.print();

    }
}

class Printer implements IPrinter {
    @Override
    public void print() {
        System.out.println("hello,proxy!");
    }
}

interface IPrinter {
    void print();
}
